//p3487验证栈序列
//第一件事：我是傻逼
#include <iostream>
using namespace std;

const unsigned int maxsize = 100000;

class stack {
private:
    int list[maxsize];
    int size;
public:
    int push(int n);
    int pop();
    int tellMetop();
    int getSize();
    stack() : size(0) { }
};

int main() {
    int times; cin >> times;
    for (int i = 0; i < times; i ++) {
        stack ss;
        int size_of_stack; cin >> size_of_stack;
        int pre_list[maxsize], lat_list[maxsize];
        for (int j = 0; j < size_of_stack; j ++) 
            cin >> pre_list[j];
        for (int j = 0; j < size_of_stack; j ++) 
            cin >> lat_list[j];
        
        //开始模拟栈的运行
        int k = 0;
        for (int j = 0; j < size_of_stack; j ++) {
            ss.push(pre_list[j]);
            while (ss.getSize() > 0 && ss.tellMetop() == lat_list[k]) {
                ss.pop();
                k ++;
            }
        }
        if (k == size_of_stack) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

//下面完成基础组件
int stack::push(int n) {
    this->list[this->size ++] = n;
    return 1; 
}

int stack::pop() {
    if (size == 0) return -1;
    return this->list[-- this->size];
}

int stack::tellMetop() {
    if (this->size <= 0) return -1;
    return this->list[this->size - 1];
}

int stack::getSize() {
    return this->size;
}